package com.dxh.common;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class VTConstant {
	private static Logger logger = LoggerFactory.getLogger(VTConstant.class);
	
	//au模块host
	public static String OLC_AU_HOST = null;
	
	//au模块port
	public static String OLC_AU_PORT = null;
	
	//分页显示条目数量
	public static int PAGE_SIZE = 10;
	
	//用户认证的首页
	public static String OLC_AU_INDEX = null;
	
	//用户认证的url
	public static String OLC_AU_LOGIN = null;
	
	//退出登录的url
	public static String OLC_AU_LOGOUT = null;
	
	//用户注册的url
	public static String OLC_AU_REGIST = null;
	
	//找回密码url
	public static String OLC_AU_RetrievePwd = null;
	
	/**
	 * 上传头像的页面，需要在链接后直接加上token（不需要加？或&）.
	 */
	public static String OLC_AU_PreUploadFace = null;
	
	/**
	 * 获取头像的servlet地址，需要在链接后加上头像参数（?faceId=参数值一般是用户id）.
	 */
	public static String OLC_AU_FaceBrowseServlet = null;
	
	static{
		InputStream inputFile = null;
		Properties prop = new Properties();
		try {
			inputFile = VTConstant.class.getClassLoader().getResourceAsStream("auConstants.properties");
			prop.load(inputFile);
			OLC_AU_HOST = prop.getProperty("au.host");
			OLC_AU_PORT = prop.getProperty("au.port");
			String auServerPath = "http://" + OLC_AU_HOST + ":" + OLC_AU_PORT;
			
			Set<?> keys = prop.keySet();
			for(Object k : keys){
				String key = (String)k;
				String value = prop.getProperty(key);
				if("page.size".equals(key)){
					PAGE_SIZE = Integer.parseInt(value);
				}else if("olc.au.index".equals(key)){
					if(!value.startsWith("http")){
						value = auServerPath + value;
					}
					OLC_AU_INDEX = value;
				}else if("olc.au.login".equals(key)){
					if(!value.startsWith("http")){
						value = auServerPath + value;
					}
					OLC_AU_LOGIN = value;
				}else if("olc.au.logout".equals(key)){
					if(!value.startsWith("http")){
						value = auServerPath + value;
					}
					OLC_AU_LOGOUT = value;
				}else if("olc.au.regist".equals(key)){
					if(!value.startsWith("http")){
						value = auServerPath + value;
					}
					OLC_AU_REGIST = value;
				}else if("olc.au.retrievePwd".equals(key)){
					if(!value.startsWith("http")){
						value = auServerPath + value;
					}
					OLC_AU_RetrievePwd = value;
				}else if("olc.au.preUploadFace".equals(key)){
					if(!value.startsWith("http")){
						value = auServerPath + value;
					}
					OLC_AU_PreUploadFace = value;
				}else if("olc.au.faceBrowseServlet".equals(key)){
					if(!value.startsWith("http")){
						value = auServerPath + value;
					}
					OLC_AU_FaceBrowseServlet = value;
				}
			}
		} catch (FileNotFoundException e) {
			logger.error("au模块常量类对应属性文件加载失败！");
		} catch (IOException e) {
			logger.error("au模块常量类对应属性文件读取时错误！");
		}
		
	}
	
}
